package com.li.configserve.config.mybatis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Description：Sql 完整输出sql
 * @Author：LiDong
 * @Create：2020/12/26
 * @Version：1.0.0
 */
@SuppressWarnings("ALL")
@Configuration
@Component
public class SqlLoogerConfig {

    private static final String SQL_TYPE_ONE = "1";

    @Autowired
    private Environment env;

    @Value("${sqllog.type)")
    private String sqllogType;

    @Bean
    public SqlInterceptor sqlInterceptor() {
        try {
            String property = env.getProperty("sqllog.type");
            if(Objects.isNull(property)){
                property = SQL_TYPE_ONE;
            }
            return new SqlInterceptor(property);
        } catch (Exception e) {
            return null;
        }
    }


}
